//
//  SJBaseHiddenVC.swift
//  SJNavigationBarDemo
//
//  Created by swordjoy on 2017/4/29.
//  Copyright © 2017年 swordjoy. All rights reserved.
//

import UIKit

class SJBaseHiddenVC: UIViewController {

  fileprivate var navigationBar: UINavigationBar!
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    automaticallyAdjustsScrollViewInsets = false
    create()
  }
  
  override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    
    view.bringSubview(toFront: navigationBar)
  }
  
  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    navigationController?.setNavigationBarHidden(true, animated: true)
  }
  
  override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    
    navigationController?.setNavigationBarHidden(false, animated: true)
  }

}

// MARK: - fileprivate

extension SJBaseHiddenVC {
  
  fileprivate func create() {
    
    navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 64))
    navigationBar.alpha = 0
    view.addSubview(navigationBar)
  }
  
}
